/*
 * Description: frequency increasing handler
 */
#include "frequency_increasing_accelerator.h"
#include "Windows.h"
#include "log.h"

namespace PERF {
void FrequencyIncreasingAccelerator::Init(std::shared_ptr<WINCONTROL::SendToHost> sendtoHost)
{
    if (sendtoHost == nullptr) {
        LOG_ERR("[PERF - Init] - sendtoHost is null!");
    }
    m_sendtoHost = sendtoHost;
}

bool FrequencyIncreasingAccelerator::OnBegin(std::shared_ptr<PerfInfo> perfInfo)
{
    LOG_INFO("[PERF - OnBegin] - start.");
    if (perfInfo == nullptr) {
        LOG_ERR("[PERF - OnBegin] - Error Occurred, perfInfo is null!");
        return false;
    }
    if (perfInfo->scene == PERF::PERF_SCENE::APP_INSTALL) {
        LOG_INFO("[PERF - OnBegin] - meet install scene");
        return false;
    }
    if (m_sendtoHost == nullptr) {
        LOG_INFO("[PERF - OnBegin] - Error Occurred, m_sendtoHost is null!");
        return false;
    }
    m_sendtoHost->SendPerfRequestToHost(perfInfo->sceneStr, perfInfo->appName, true);
    LOG_INFO("[PERF - OnBegin] - succeed.");
    return true;
}

bool FrequencyIncreasingAccelerator::OnEnd(std::shared_ptr<PerfInfo> perfInfo)
{
    LOG_INFO("[PERF - OnEnd] - start.");
    if (perfInfo == nullptr) {
        LOG_ERR("[PERF - OnEnd] - Error Occurred, perfInfo is null!");
        return false;
    }
    if (perfInfo->scene == PERF::PERF_SCENE::APP_INSTALL) {
        LOG_INFO("[PERF - OnEnd] - meet install scene");
        return false;
    }
    if (m_sendtoHost == nullptr) {
        LOG_ERR("[PERF - OnEnd] - Error Occurred, m_sendtoHost is null!");
        return false;
    }
    m_sendtoHost->SendPerfRequestToHost(perfInfo->sceneStr, perfInfo->appName, false);
    LOG_INFO("[PERF - OnEnd] - succeed.");
    return true;
}
}  // namespace PERF